<script>
/**
 * title
 * @return {[type]} [description]
 */
export default{
	components:{
		
	},
	props:{

	},
	data(){
		return {
			visible:false,
			data:{},
			loading:false,
			sellis:[],
		}
	},
	created(){},
	mounted(){},
	methods:{
		send(){
			this.$refs.forms.validate().then(async ()=>{
				console.log('验证通过');
				this.loading=true;
				let rs = await this.muajax.YscSave({
					...this.data,
				});
				this.loading=false;
				if(rs.status==200){
					this.$message.success(rs.msg);
					this.visible=false;
					this.$emit('reload')
				}
			}).catch(err=>{
				console.log('验证不通过');
				// this.$errorFocus(err);
			})
		},
		show(show,param,list){
			this.visible=show;
			if(show){
				this.sellis=JSON.parse(JSON.stringify(list));
				this.data={sort:10,};
				this.param=param;
				this.data.fid=this.param?.fid||null;
				if(!!this.param?.id){
					this.data.id=this.param.id;
					this.dischild(this.data.id);
					this.data.name=this.param.name;
					this.data.sort=this.param.sort;
				}
			}
		},
		dischild(id){
			if(!id){
				return false
			}
			for (let i = 0; i < this.sellis.length; i++) {
				if(id==this.sellis[i].id){
					this.sellis[i].dis=true;
				}
				if(id==this.sellis[i].fid){
					this.dischild(this.sellis[i].id);
					this.sellis[i].dis=true;
				}
			}
		},//不可选择选项
	},
	computed:{},
	watch:{},
	filters:{},
}
</script>
<template>
	<a-modal
		v-model:visible="visible"
		width="800px"
		title="分类管理"
		:maskClosable="false"
		@ok="send"
		cancelText="取消"
		okText="提交"
		:confirmLoading="loading"
	>
		<a-form
		ref="forms"
		:model="data"
		>
			<a-form-item
				label="选择父级分类"
				:labelCol="{span: 4}"
			>
				<a-select
					placeholder="请选择分类（留空为顶级）"
					:dropdownMatchSelectWidth="false"
					v-model:value="data.fid"
					:allowClear="true"
				>
					<a-select-option v-for="v in sellis" :key="v.id" :value="v.id" :disabled="v.dis">{{ v.prefixname }}</a-select-option>
				</a-select>
				
			</a-form-item>
			<a-form-item
				label="分类名称"
				:labelCol="{span: 4}"
				name="name"
				:rules="[{required:true,message:'请输入分类名称'}]"
			>
				<a-input
					placeholder="请输入"
					v-model:value="data.name"
				/>
			</a-form-item>
			<a-form-item
				label="排序"
				:labelCol="{span: 4}"
				name="sort"
				:rules="[{required:true,type:'number',message:'请输入排序'}]"
			>
				<a-input-number
					:defaultValue="10"
					placeholder="请输入"
					v-model:value="data.sort"
					:min="0"
					:max="9999"
				/>
			</a-form-item>
		</a-form>
	</a-modal>
</template>
<style lang="less" scoped>

</style>